#ifndef MULTISELECTCOMBOBOX_H
#define MULTISELECTCOMBOBOX_H

#include <QComboBox>
#include <QListWidget>
#include <QLineEdit>
#include <QLabel>
#include <QEvent>

#include <QCheckBox>
#include <QHBoxLayout>
#include <QSpacerItem>
#include <QPushButton>

class CheckBoxWidget : public QWidget {
    Q_OBJECT
public:
    CheckBoxWidget(QWidget *parent = nullptr);
    ~CheckBoxWidget();

    void setText(const QString &getText);
    QString getText() const;
    bool isChecked() const;
    void setColor(const QColor getColor = Qt::color0);
    QColor getColor() const;
    QPen getPen() const;
    void setSize(int width = 150, int height = 50);
signals:
    void stateChanged(int state);

private:
    virtual bool eventFilter(QObject *obj, QEvent *e) override;
    QCheckBox *m_check_box;
    QLabel *m_label;
    QPen m_pen;
    QHBoxLayout *m_layout;
    QSpacerItem *m_spacer;
};

class MultiSelectComboBox : public QComboBox
{
    Q_OBJECT
public:
    explicit MultiSelectComboBox(QWidget *parent = nullptr);
    ~MultiSelectComboBox();

    int addItem(const QString &item, const QColor color = Qt::color0);
    int addItems(const QStringList &items);

    /* 获取当前选中的条目名称 */
    QStringList currentItems() const;
    int getItemAttr(const QString name, QPen &pen);

    void setPlaceHolderText(const QString label);
    void setItemChecked(const QString &item) { Q_UNUSED(item); }
    void setItemsChecked(const QStringList &items) {Q_UNUSED(items); }

    void resetSelection() {}
    /* 重写了清理函数 */
    void clear();

signals:
    /* 信号发出时，带有此次被改变的 CheckBoxWidget 的 text, 以及选中的状态 */
    void selectedChange(const QString item, bool checked);

private slots:
    /* m_list_widget 内 CheckBoxWidget 选中改变时，引发该槽函数，随即发出 selectChange 信号 */
    void itemClicked();

private:
    QListWidget *m_list_widget;
    QLineEdit *m_edit;
};

#endif // MULTISELECTCOMBOBOX_H
